package com.cn.xiaonuo.slbfinances.slbunions.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.cn.xiaonuo.common.entity.BusinessMessage;
import com.cn.xiaonuo.common.utils.DateTimeUtils;
import com.cn.xiaonuo.dbs.core.annotation.DataSource;
import com.cn.xiaonuo.slbfinances.slbunions.entity.SlLmOrder;
import com.cn.xiaonuo.slbfinances.slbunions.mapper.LmMapper;
import com.cn.xiaonuo.slbfinances.slbunions.mapper.SlLmOrderMapper;
import com.cn.xiaonuo.slbfinances.slbunions.service.ILmOrderService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

@Service
public class LmOrderServiceImpl extends ServiceImpl<SlLmOrderMapper, SlLmOrder> implements ILmOrderService {

    @Autowired
    private LmMapper lmMapper;

    @Override
    @DataSource(name = "jyb_soole_data_hn")
    public BusinessMessage selectLmOrderInfo(String userId, String  orderId, Long beginTime, Long endTime, Integer pageNum, Integer pageSize) {
        BusinessMessage message = new BusinessMessage();
        try {
            if (null == pageNum || pageNum <= 1) {
                pageNum = 1;
            }
            if (null == pageSize || pageSize <= 1) {
                pageSize = 10;
            }
            String btime="";
            String etime="";
            if(null!=beginTime&&null !=endTime){
                Map<String,String> map=  DateTimeUtils.conversionTime(beginTime,endTime);
                btime=map.get("begin");
                etime=map.get("end");
            }
            // 设置分页参数
            PageHelper.startPage(pageNum, pageSize);
            List<Map<String, Object>> mapList = lmMapper.selectLmOrderInfo(userId,orderId,btime,etime);
            PageInfo<Map<String, Object>> map = new PageInfo<>(mapList);
            message.setData(map);
            message.setMessage("操作成功");
            message.setSuccess(true);
        } catch (Exception e) {
            message.setMessage("操作失败");
            message.setSuccess(false);
            e.printStackTrace();
        }
        return message;
    }

}
